home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / objkit.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  4KB  |  160 lines

  1. #include "objkit.h"
  2. #include "help.h"
  3.  
  4. #include <dos.h>
  5.  
  6. int ObjectKit::act_ret()    // returns RET_OK, RET_CANCEL and RET_MOUSE
  7.     {
  8.     switch(global_i[0])
  9.     {
  10.     case AC_OK: return RET_OK;
  11.     case AC_CANCEL:
  12.     case AC_NULL:
  13.         if(e.what == KEYEVENT)
  14.         return RET_CANCEL;
  15.         return RET_MOUSE;
  16.     default: return 0;
  17.     }
  18.     }
  19. /////////////////////////////
  20. void ObjectKit::assign(Visible* toCall, Visible* callFrom,
  21.                   int act_type)
  22.     {
  23.     int object_num = Kit::get(toCall);
  24.     callFrom->assign(object_num, act_type);
  25.     }
  26. /////////////////////////////
  27. void ObjectKit::exe(int )
  28.     {
  29.     int sub_action = 0;                            // reserv
  30.     while(1)
  31.     {
  32.     mouseShowCursor();
  33.     int res_cur = current;                     // reserv
  34.         global_num = current;
  35.     list[current]->exe(sub_action);    // event which can not be procecced
  36.     sub_action = 0;                        // with current object
  37.  
  38.     if(!current)                           // after pressing on 0th window
  39.         {                                  // - proceed with 1th
  40.         shift();
  41.         continue;
  42.         }
  43.  
  44.     if(global_i[0])            // if exe() sets action_type to global_i[0]
  45.         {
  46.         if(global_i[0] == AC_NEXT)             // command for objkit, not for any of its components
  47.         {                                  // usage: menu->find can not find the given string
  48.         moveTo(list[current]->isPoint());  // in the menu->itemList
  49.         sub_action = AC_NEXT;
  50.         continue;
  51.         }
  52.  
  53.         int res = current;                  // where to return whith ESC-like command
  54.         moveTo(list[current]->isPoint());
  55.         global_num = current;
  56.         list[current]->exe(global_i[0]); // for example: button->exe(), calls menu->exe()
  57.  
  58.         if(global_i[0] == AC_REDRAW || global_i[0] == AC_RESIZE
  59.             || global_i[0] == AC_MOVE)
  60.         {
  61.                 return;
  62.         }
  63.  
  64.         if(global_i[0] != AC_NEXT)  // return after execution, f.e. button - menu->exe(AC_LEFT) - again return to button
  65.         {
  66.         moveTo(get(list[res]));
  67.         global_num = current;
  68.         if(list[current]->isRet(act_ret()))
  69.             {
  70.             if(global_i[0] != AC_NULL)         // if !CANCEL pressed
  71.             global_i[0] = action_type;
  72.             return;
  73.             }
  74.         }
  75.         }
  76.  
  77.     if(!global_i[0])
  78.         {
  79.         if(e.what == KEYEVENT)
  80.         {
  81.         switch(e.key)
  82.             {
  83.             case EVENT_F1:
  84.             if(help_context)
  85.                 ::help(help_context);
  86.             break;
  87.             case EVENT_ALT_F3:
  88.             if(!isRet(RET_REMOVE))   // This command is for AppKit
  89.                 {                    // we simply pass it up
  90.                 global_i[0] = 0;
  91.                 return;
  92.                             }
  93.             global_i[0] = AC_ERASE;  // We will remove this object
  94.             return;                  // from the AppKit
  95.             case EVENT_ALT_F4:
  96.             return;
  97.             case EVENT_F2:
  98.             case EVENT_RETURN:
  99.             if(list[current]->isRet(RET_REMOVE | RET_OK
  100.                         | RET_MOUSE))
  101.                 {
  102.                 global_i[0] = action_type;
  103.                 return;
  104.                 }
  105.             break;
  106.             case EVENT_TAB: mouseHideCursor(); shift();
  107.                 mouseShowCursor(); break;
  108.             case EVENT_F6:
  109.             case EVENT_ALT_TAB:
  110.             case EVENT_F10:
  111.             case EVENT_ESC: global_i[0] = 0; return;
  112.             default: break;
  113.             }
  114.         }
  115.         else
  116.         if(e.mouse1())    // mouse pressed
  117.             {
  118.             int n = 1;
  119.             if(!list[0]->mouse_in(e.where()))  // outside
  120.             {
  121.             global_i[0] = AC_CLOSE;
  122.             return;
  123.             } // mouse pressed outside
  124.             while(n != used + 1)   // where it was pressed?
  125.             {
  126.             if(list[current]->mouse_in(loc(e.where())))
  127.                 {
  128.                 if(res_cur == current
  129.                    && list[current]->isRet(RET_MOUSE))
  130.                 {
  131.                 global_i[0] = action_type;
  132.                 return;
  133.                 }
  134.                 break;
  135.                 }
  136.             mouseHideCursor(); shift(); mouseShowCursor();    n++;
  137.             }
  138.             if(n == used + 1)
  139.             {
  140.             current = 0;               // if background object pressed -
  141.             if(help_context)           // we check it last, and try
  142.                 ::help(help_context);  // to show help
  143.             }
  144.             }
  145.         }
  146.     }
  147.     }
  148. ////////////////////
  149. void ObjectKit::show()
  150.     {
  151.     mouseHideCursor();
  152.     if(list[0] != 0)
  153.     list[0]->show();
  154.     for(int i = 1; i <= used; i++)   // attention !!!  0 - base window
  155.     list[i]->show();
  156.     moveTo(1);
  157.     mouseShowCursor();
  158.     }
  159. /////////////////////
  160.